#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import re

def myprint(obj, end='\n'):
    sys.stdout.write(str(obj) + end)

def main():
    pt=re.compile(r'<ProductDetail brand="([^\"]*)"\s+.*title="([^\"]*)"')
    v='''
<ProductDetail brand="品胜" category="首页|电脑整机首页|电脑整机|笔记本配件" id="106537" model="S195B90" price="199.0" productID="189709" siteName="360buy" title="品胜笔记本电脑电源适配器S195B90 适用于索尼笔记本电脑" url="http://www.360buy.com/product/189709.html"/>
<ProductDetail brand="维氏" category="首页|日用百货首页|礼品箱包|瑞士军刀" color="黄色" id="106538" model="救生员0.8623.MWN(荧光刀柄带尼龙刀套)" price="409.0" productID="189704" siteName="360buy" title="瑞士军刀救生员0.8623.MWN(荧光刀柄带尼龙刀套)" url="http://www.360buy.com/product/189704.html"/>
<ProductDetail brand="" category="首页|日用百货首页|礼品箱包|瑞士军刀" color="黄色" id="106538" model="救生员0.8623.MWN(荧光刀柄带尼龙刀套)" price="409.0" productID="189704" siteName="360buy" title="test" url="http://www.360buy.com/product/189704.html"/>
'''
    myprint('--first method:')
    for it in v.strip().split('\n'):
        t=pt.search(it)
        if t:
            myprint(t.groups())

    myprint('--second method:')
    pt=re.compile(r'<ProductDetail brand="([^\"]*)"\s+.*title="([^\"]*)"',re.M)
    for m in pt.finditer(v.strip()):
        myprint(m.groups())


if __name__ == '__main__':
    main()
    myprint('--done')